package com.sun.controller.admin;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.pojo.Floor;
import com.sun.pojo.Menu;
import com.sun.pojo.Role;
import com.sun.service.FloorService;
import com.sun.service.MenuService;
import com.sun.service.RoleService;
import com.sun.utils.DataGridViewResult;
import com.sun.utils.SystemConstant;
import com.sun.utils.TreeNode;
import com.sun.vo.FloorVo;
import com.sun.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/floor")
public class FloorController {

    @Autowired
    private FloorService floorService;

    @RequestMapping("/findAll")
    public DataGridViewResult findAll(FloorVo floorVo){
        DataGridViewResult all = floorService.findAll(floorVo);
        return all;
    }

    @RequestMapping("/addFloor")
    public String addFloor(Floor floor){
        HashMap<String, Object> map = new HashMap<String, Object>();
        int i = floorService.addFloor(floor);
        if(i>0){
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"添加成功!");
        }else{
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"添加失败!");
        }
        return JSON.toJSONString(map);
    }

    @RequestMapping("/updateFloor")
    public String updateFloor(Floor floor){
        HashMap<String, Object> map = new HashMap<String, Object>();
        int i = floorService.updateFloor(floor);
        if(i>0){
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"修改成功!");
        }else{
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"修改失败!");
        }
        return JSON.toJSONString(map);
    }

    @RequestMapping("/initRoomSelectFloor")
    public String initRoomSelectFloor(){
        return JSON.toJSONString(floorService.initRoomSelectFloor());
    }
}
